package com.his.his_system.controller.VisitController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.his.his_system.common.util.ResultAdvice;
import com.his.his_system.controller.VisitController.DefaultBean.ChangeJsonAndObject;
import com.his.his_system.controller.VisitController.DefaultBean.MedicineList;
import com.his.his_system.controller.VisitController.DefaultBean.Obj;
import com.his.his_system.domain.DzmHisDoctor;
import com.his.his_system.domain.DzmHisInspectionfee;
import com.his.his_system.domain.DzmHisMedicines;
import com.his.his_system.service.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 新开就诊
 * @author 余襄元
 */
@RestController
@RequestMapping("/his/sad/seedoctor/")
@Slf4j
public class SeeDoctorController {
    @Resource
    private DefaultService defaultService;

    @Resource
    private DzmHisMedicinesService dzmHisMedicinesService;

    @Resource
    private DzmHisDoctorService dzmHisDoctorService;

    @Resource
    private DzmHisInspectionfeeService dzmHisInspectionfeeService;

    @Resource
    private  YxyTodo yxyTodo;

    @Resource
    private DzmHisPrescriptionExtrachargesService dzmHisPrescriptionExtrachargesService;
    /**
     * 获取所有药品和库茨纳
     * @return
     */
    @GetMapping("getMedicinesList")
    public ResultAdvice<List<DzmHisMedicines>> getMedicinesList(){
        return ResultAdvice.success(dzmHisMedicinesService.display(),"成功");

    }

    /**
     * 获取今天未就诊患者列表
     * @return
     */
    @GetMapping("getAllRegisterToday")
    public ResultAdvice getAllRegisterToday(Integer i){
        return ResultAdvice.success(defaultService.getAllVisit(i,null,null,"today"),"成功");
    };

    /**
     * 获取今天已就诊患者列表 包括挂号和未挂号
     * @return
     */
    @GetMapping("getAllRegisterToday2")
    public ResultAdvice getAllRegisterToday2(String namephp){
        return ResultAdvice.success(defaultService.getAllRegisterToday2(namephp),"成功");

    }

    /**
     * 获取当前医生信息
     * @return
     */
    @RequestMapping("getNewdoctorinfo")
    public ResultAdvice getNewdoctorinfo(){
        QueryWrapper<DzmHisDoctor> queryWrapper = new QueryWrapper();
        queryWrapper.eq("id",yxyTodo.getDoctorid());
        return ResultAdvice.success(dzmHisDoctorService.getOne(queryWrapper),"成功");
    }


    /**
     * 模糊查询获取今天和未就诊患者列表
     * @return
     */
    @GetMapping("selectbynameOrphp")
    public ResultAdvice selectbynameOrphp(Integer i,String namephp){
        return ResultAdvice.success(defaultService.getAllVisit1(i,namephp,"today"),"成功");
    };

    /**
     * 获取医院所有检查项目
     * @return
     */
    @GetMapping("getAllInspection")
    public ResultAdvice<List<DzmHisInspectionfee>> getAllInspection(){
        QueryWrapper<DzmHisInspectionfee> queryWrapper=new QueryWrapper();
        queryWrapper.eq("hid",yxyTodo.getHospitalid());
        return ResultAdvice.success(dzmHisInspectionfeeService.list(queryWrapper),"成功");
    }

    /**
     * 开单
     */
    @PostMapping("billing")
    public ResultAdvice billing(@RequestBody Obj obj){
        return defaultService.billing(obj.getStr(),obj.getList(),obj.getMoney());
    }


    /**
     * 获取附加费项目列表
     */
    @GetMapping("getAllext")
    public ResultAdvice getAllext(){
        try{
            return ResultAdvice.success(dzmHisPrescriptionExtrachargesService.list(),"成功");
        }catch (Exception e){
            log.error("获取附加费项目列表失败");
            return ResultAdvice.fail("获取附加费项目列表失败");
        }
    }
}
